package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.player.*;
import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

public class VehicleSoulPb {

	public static VehicleProto.VehicleSoulSyncMsg.Builder parseVehicleSoulSyncMsg(List<UserVehicleSoul> soulList,boolean isOneKey, int composeBd) {
		if(null == soulList){
			return null;
		}
		VehicleProto.VehicleSoulSyncMsg.Builder respMsg = VehicleProto.VehicleSoulSyncMsg.newBuilder();
		respMsg.setIsOneKeyCompose(isOneKey);
		respMsg.setFourLvSoulComposeRemainNum(composeBd);
		for(UserVehicleSoul soul : soulList){
			VehicleProto.VehicleSoulTempMsg.Builder aMsg = parseVehicleSoulTempMsg(soul);
			if(aMsg != null){
				respMsg.addSouls(aMsg);
			}
		}
		return respMsg;
	}

	public static VehicleProto.VehicleSoulTempMsg.Builder parseVehicleSoulTempMsg(UserVehicleSoul soul) {
		if(null == soul){
			return null;
		}
		VehicleProto.VehicleSoulTempMsg.Builder soulMsg = VehicleProto.VehicleSoulTempMsg.newBuilder();
		soulMsg.setSoulId(soul.getSoulId());
		soulMsg.setId(soul.getConfigId());
		soulMsg.addAllOccs(soul.getOccList());
		soulMsg.setIsLock(soul.isLock());

		if(soul.getEntryMap().size() > 0){
			for(int index = 0;index < soul.getEntryMap().size();index++){
				if(soul.getEntryMap().containsKey(index)){
					List<Integer> infoList = soul.getEntryMap().get(index);
					VehicleProto.VehicleSoulEntryTempMsg.Builder entryMsg = VehicleProto.VehicleSoulEntryTempMsg.newBuilder();
					entryMsg.setOcc(infoList.get(1));
					entryMsg.setValue(infoList.get(2));
					entryMsg.setWashTimes(infoList.get(3));
					if(infoList.size() == 6){
						entryMsg.setTempOcc(infoList.get(4));
						entryMsg.setTempValue(infoList.get(5));
					}
					soulMsg.addEntrys(entryMsg);
				}else{
					break;
				}
			}
		}

		if(!StringUtils.isNullOrEmpty(soul.getVehicleId())){
			VehicleProto.VehicleSoulEquipMsg.Builder equipMsg = VehicleProto.VehicleSoulEquipMsg.newBuilder();
			equipMsg.setVehicleId(soul.getVehicleId());
			equipMsg.setEquipTime(soul.getEquipTime());
			equipMsg.setPos(soul.getEquipPos());
			soulMsg.setEquip(equipMsg);
		}

		return soulMsg;
	}

}
